package example;
import org.w3c.dom.Node;
import facecat.topin.btn.*;
import facecat.topin.core.*;
import facecat.topin.tab.*;
import facecat.topin.xml.*;
import facecat.topin.swing.*;

/*
* 复选按钮示例
 */
public class CheckBoxExample extends FCUIXml implements FCEventCallBack
{
    /*
     * 加载Xml
     * @param fileName 文件名
     * @param view 视图名称
     */
    public void loadXml(String fileName, FCView view)
    {
        setScript(new FaceCatScript(this));
        super.loadXml(fileName, view);
        //获取第二页
        FCTabPage tabPage = getTabPage("TabPage2");
        FCCheckBox checkBox = new FCCheckBox();
        checkBox.setLocation(new FCPoint(100, 100));
        checkBox.setSize(new FCSize(100, 20));
        tabPage.addView(checkBox);
        checkBox.setText("选项");
        checkBox.setChecked(true);

        //从Xml中获取按钮
        FCCheckBox button1 = getCheckBox("CheckBox");
        FCCheckBox button2 = getCheckBox("CheckBox2");
        FCCheckBox button3 = getCheckBox("CheckBox3");
        FCCheckBox button4 = getCheckBox("CheckBox4");

        //绑定选项改变事件
        button1.addEvent(this, FCEventID.CheckedChanged, this);
        button2.addEvent(this, FCEventID.CheckedChanged, this);
        button3.addEvent(this, FCEventID.CheckedChanged, this);
        button4.addEvent(this, FCEventID.CheckedChanged, this);
        checkBox.addEvent(this, FCEventID.CheckedChanged, this);
    }

    /*
     * 创建视图
     * @param node 节点
     * @param type 类型
     */
    public FCView createView(Node node, String type)
    {
        if (type.equals("mycheckbox"))
        {
            return new MyCheckBox();
        }
        return super.createView(node, type);
    }

    /*
     * 事件
     * @param eventName 事件ID
     * @param sender 发送者
     * @param invoke 引用者
     */
    public void callEvent(String eventName, Object sender, Object invoke)
    {
        FCCheckBox checkBox = (FCCheckBox)sender;
    }
}
